let set = function (key, value) {
  try {
    if (typeof value == 'object') {
      sessionStorage.setItem(key, JSON.stringify(value));
    } else {
      sessionStorage.setItem(key, value);
    }
  } catch (e) {
    sessionStorage.setItem(key, value);
  }
};
let get = function (key, defaultValue = '') {
  let value = sessionStorage.getItem(key) || defaultValue;
  try {
    return JSON.parse(value);
  } catch (e) {
    return value;
  }
};
/**
 * sessionStorage 取值后，移除此值
 */
let getThenRemove = function (key) {
  let ret = get(key);
  remove(key);
  return ret;
};
let remove = function (key) {
  sessionStorage.removeItem(key);
};

export const ss = {
  set,
  get,
  getThenRemove,
  remove,
};
